<?php
  /*
   Plugin Name: Steel
   Version: 0.1
   Plugin URI: http://dangkhoaweb.com
   Author: Đăng Khoa
   Author URI: http://dangkhoaweb.com
   Description: Steel
   */
  global $wp_version;
  $exit_msg = 'Steel require WordPress 3.1 or newer.
              <a href="http://codex.wordpress.org/
              Upgrading_WordPress">Please update!</a>';
if (version_compare($wp_version, "3.1", "<"))
{
   exit($exit_msg);
}
// Avoid name collisions.
  if ( !class_exists('steel') ) :
  class steel
  {
  // this variable will hold url to the plugin
          var $plugin_url;
          // Initialize the plugin
          function steel()
          {
              $this->plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname( plugin_basename(__FILE__)));
              add_action('admin_menu', array(&$this,'my_plugin_menu'));
              add_shortcode('DISPLAY', array(&$this, 'display'));
              add_action('wp_head', array(&$this, 'style') );
               if($_GET['page'] == 'steel.php')
                {
                  add_action('admin_head', array(&$this, 'css') );
                  add_action('admin_print_scripts', array(&$this, 'my_admin_scripts'));
                  add_action('admin_print_styles', array(&$this, 'my_admin_styles'));
                
                }

          }
          function my_admin_scripts() {
        wp_enqueue_script('media-upload');
        wp_enqueue_script('thickbox');
        wp_register_script('my-upload', $this->plugin_url.'/my-script.js', array('jquery','media-upload','thickbox'));
        wp_enqueue_script('my-upload');
        }

        function my_admin_styles() {
        wp_enqueue_style('thickbox');
        }


       
          function style(){
               echo '<script src="'.$this->plugin_url.'jquery-1.4.4.js"></script>
                    <script src="'.$this->plugin_url.'home.js"></script>';
                    }
        function css(){
            echo '  <link rel="stylesheet" href="'.$this->plugin_url.'base/jquery.ui.all.css">
                    <script src="'.$this->plugin_url.'jquery-1.4.4.js"></script>
                        <script src="'.$this->plugin_url.'ajax.js"></script>
                    <script src="'.$this->plugin_url.'ui/jquery.ui.core.js"></script>
                    <script src="'.$this->plugin_url.'ui/jquery.ui.widget.js"></script>
                    <script src="'.$this->plugin_url.'ui/jquery.ui.tabs.js"></script>
                    <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js"></script>';
            echo '<script>
                    jQuery(function() {
                            jQuery( "#tabs" ).tabs({
                                    ajaxOptions: {
                                    beforeSend: function(){
                                    jQuery("#loading").slideDown();
                                    },
                                            error: function( xhr, status, index, anchor ) {
                                                    jQuery( anchor.hash ).html(
                                                            "Page not found ");
                                            }
                                    }
                            });
                    });
                    </script>';
        }
        function display(){
            global $wpdb;
            $plugin_url = $this->plugin_url;
            require 'display.php';
            return $str;
        }
        function my_plugin_menu()
        {
            add_menu_page('Steele manager', 'Steele manager',1,basename(__FILE__), array(&$this, 'admin'));
        }
        function admin()
        {
            echo '<input type="hidden" name="base_url" id="base_url" value="'.$this->plugin_url.'" />
                <div id="tabs">
                <ul>
                        <li><a href="'.$this->plugin_url.'list.php">Listing manager</a></li>
                        <li><a href="'.$this->plugin_url.'attribute.php">Attribute Manager</a></li>
                        
                </ul>
                <div id="tabs-1">
                </div>
        </div>
';
        }
      function install()
      {
          global $wpdb;
          $wpdb->query("CREATE TABLE `wp_house` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`name` VARCHAR( 255 ) NOT NULL ,`code` VARCHAR( 255 ) NOT NULL ,`address` TEXT NOT NULL,`description` TEXT NOT NULL,`date` DATETIME NOT NULL,`bed_room` INT( 3 ) NOT NULL ,`type` INT( 3 ) NOT NULL ,`location` INT( 3 ) NOT NULL ,`price` BIGINT( 15 ) NOT NULL,`image` TEXT NOT NULL)");
          $wpdb->query("CREATE TABLE `wp_attribute` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`name` VARCHAR( 255 ) NOT NULL ,`category` INT NOT NULL);");
          $wpdb->query("CREATE TABLE `wp_value` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`id_att` INT NOT NULL ,`id_house` INT NOT NULL)");
          $wpdb->query("CREATE TABLE `wp_category` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`name` VARCHAR( 255 ) NOT NULL)");
          $wpdb->query("CREATE TABLE `wp_image` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`id_house` INT NOT NULL ,`link` TEXT NOT NULL ,`main` INT( 1 ) NOT NULL) ");
          
          }
  }
  else :
      exit ("Class stell exists");
  endif;
  $steel = new steel();
  if (isset($steel))
    {
       register_activation_hook( __FILE__, array(&$steel,'install') );
    }
?>